from SqliteHandler import SqliteHandler


class QuotaReader:

    def __init__(self, path):
        sql = SqliteHandler(path)
        self.data = sql.select('表三甲', flag='list', tostring=True)
        self.dataB = sql.select('表三乙', flag='list', tostring=True)
        self.dataC = sql.select('表三丙', flag='list', tostring=True)

    def getpro(self):

        retset = [i[1] for i in self.data]
        retset = set(retset)
        retset = list(retset)
        retset.sort()

        return retset

    def getquota(self, pro):

        relist = []
        for i in self.data:
            if i[1] == pro:
                relist.append(i[5:-1])

        return relist

    def getcolnames(self, name):
        if name == '表三甲':
            return ('编号', '名称', '单位', '技工', '普工', '正常系数', '拆除入库系数', '拆除不入库系数')
        elif name == '表三乙' or name == '表三丙':
            return ('是否关联', '编号', '名称', '单位', '机械/仪表名称', '消耗台班', '单价', )

    def getmach(self):
        relist = []
        for i in self.dataB:
            relist.append(i[2:8])

        return relist

    def getmeter(self):
        relist = []
        for i in self.dataC:
            relist.append(i[2:8])

        return relist

